import { apiGet, apiPost, apiPut, apiDelete } from './client'

export interface Major {
  id?: number
  deptId?: number
  code?: string
  name?: string
}

type BoPage<T> = { pageNum: number; pageSize: number; total: number; pages: number; list: T[] }

export async function listMajors(params: { deptId?: number; keyword?: string; pageNum: number; pageSize: number }) {
  const page = await apiGet<BoPage<Major>>('/api/grades/majors/page', params)
  return { items: page.list || [], total: page.total || 0 }
}

export async function getMajor(id: number) {
  return apiGet<Major>(`/api/grades/majors/${id}`)
}

export async function createMajor(major: Major) {
  return apiPost<Major>('/api/grades/majors', major)
}

export async function updateMajor(id: number, major: Major) {
  return apiPut<Major>(`/api/grades/majors/${id}`, major)
}

export async function deleteMajor(id: number) {
  return apiDelete<string>(`/api/grades/majors/${id}`)
}